package com.ruoyi.business.domain.vo;

import cn.hutool.core.collection.CollUtil;
import com.ruoyi.common.core.domain.TreeEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 档案目录对象 doc_directory
 *
 * @author ruoyi
 * @date 2024-11-07
 */

@Data
@EqualsAndHashCode(callSuper = true)
public class DocDirectoryVo extends TreeEntity<DocDirectoryVo> {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    private Long id;

    /**
     * 名称
     */
    private String name;

    private String coverImg;

    private String path;

    /**
     * 备注
     */
    private String remarks;

    /**
     * 上传状态
     */
    private String status;

    /**
     * 人员ID
     */
    private Long personId;

    /**
     * 材料形成时间
     */
    private Date fileFromTime;

    public void fillByPersonFileVo(List<PersonFileVo> personFileVos) {
        if (CollUtil.isNotEmpty(personFileVos)) {
            personFileVos = personFileVos.stream().sorted((o1, o2) -> o2.getFileFromTime().compareTo(o1.getFileFromTime())).collect(Collectors.toList());
            PersonFileVo personFileVo = personFileVos.get(0);
            this.setStatus(personFileVo.getStatus());
            this.setUpdateTime(personFileVo.getUpdateTime());
            this.setFileFromTime(personFileVo.getFileFromTime());
        } else {
            this.setStatus("未上传");
            this.setUpdateTime(null);
            this.setFileFromTime(null);
        }
    }


}
